﻿using DelonixRegiaSystem.Classes;
using DelonixRegiaSystem.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;
using System.Data.SqlClient;


namespace DelonixRegiaSystem
{
    public partial class AdminMainMenu : Form
    {

        public AdminMainMenu()
        {
            InitializeComponent();

            string dutyType = "Room";
            string Status = "Occupied";
            ArrayList room = new ArrayList();
            room = roomAvailabilityDBManager.GetAllRooms();
            foreach (room r in room)
            {
                CBEditRoomNum.Items.Add(Convert.ToString(r.roomNum));
                CBListAllGuest.Items.Add(Convert.ToString(r.roomNum));
                CBRoomAvailDelete.Items.Add(Convert.ToString(r.roomNum));
                CBHousekeepingCreate.Items.Add(Convert.ToString(r.roomNum));
                housekeepingNum2.Items.Add(Convert.ToString(r.roomNum));
            }
            ArrayList staff = new ArrayList();
            staff = housekeepingJhDBManager.GetStaffByDutyType(dutyType);
            foreach (staff s in staff)
            {
                CBHousekeepingCreateStaff.Items.Add(s.staffName);
                CBHousekeepingUpdate.Items.Add(s.staffName);
                housekeepingNum3.Items.Add(s.staffName);
            }
            ArrayList status = new ArrayList();
            status = ReportingDBManager.GetRoomReportStatus(Status);
            foreach (room s in status)
            {
                CBListGuestInRoomReport.Items.Add(s.roomNum);
            }
            lblDateTime.Text = DateTime.Now.ToString();
        }

        #region JIAN HAO'S CODES
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string Status = Convert.ToString(comboBox1.SelectedItem);
            ArrayList room = new ArrayList();
            room = ReportingDBManager.GetRoomReportStatus(Status);
            dataGridView1.DataSource = room;
        }

        private void AdminMainMenu_Load(object sender, EventArgs e)
        {

            // TODO: This line of code loads data into the 'bookinNew.booking' table. You can move, or remove it, as needed.
            
            // TODO: This line of code loads data into the 'delorixDataSet.room' table. You can move, or remove it, as needed.



        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void btnExportRoomStatus_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();

            Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
            Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
            app.Visible = true;
            worksheet = workbook.Sheets["Sheet1"];
            worksheet = workbook.ActiveSheet;
            worksheet.Name = "Exported from gridview";

            for (int i = 1; i < dataGridView1.Columns.Count + 1; i++)
            {
                worksheet.Cells[1, i] = dataGridView1.Columns[i - 1].HeaderText;
            }
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                for (int j = 0; j < dataGridView1.Columns.Count; j++)
                {
                    worksheet.Cells[i + 2, j + 1] = dataGridView1.Rows[i].Cells[j].Value.ToString();
                }
            }
            workbook.SaveAs("C:\\Users\\1104882d\\Desktop\\RoomStatus.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing);


            //for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
            //{
            //    for (int j = 0; j < dataGridView1.Columns.Count; j++)
            //    {
            //        worksheet.Cells[i + 2, j + 1] = dataGridView1.Rows[i].Cells[j].Value.ToString();
            //    }
            //}
        }

        private void btnListGuestRoom_Click(object sender, EventArgs e)
        {
            if (CBListGuestInRoomReport.Text != "")
            {
                int roomNum = Convert.ToInt32(CBListGuestInRoomReport.SelectedItem);
                guest g = new guest();
                g = ReportingDBManager.GetGuestInRoom(roomNum);
                lblListGuestRoomNum1.Text = Convert.ToString(g.roomNum);
                lblListGuestFirstName1.Text = g.firstName;
                lblListGuestLastName1.Text = g.lastName;
                lblListGuestPhoneNum1.Text = Convert.ToString(g.phoneNo);
                lblListGuestCountry1.Text = g.country;
                lblListGuestCheckIn1.Text = Convert.ToString(g.checkIn);
                lblListGuestCheckOut1.Text = Convert.ToString(g.checkOut);
            }
            else
            {
                MessageBox.Show("Please choose a room");
            }
        }

        private void btnCreateRoom_Click(object sender, EventArgs e)
        {
            if (tbxCreateRMFloor.Text != "" && tbxCreateRMType.Text != "" && tbxCreateRoomRates.Text != "")
            {
                string Status = Convert.ToString(CBCreateRMStatus.SelectedItem);
                string roomType = tbxCreateRMType.Text;
                string roomFloor = tbxCreateRMFloor.Text;
                string roomRates = tbxCreateRoomRates.Text;
                room r = new room() { Status = Status, roomType = roomType, roomFloor = roomFloor, roomRates = Convert.ToInt32(roomRates) };
                roomAvailabilityDBManager.InsertRoom(r);
                MessageBox.Show("Room Created!");
                CBEditRoomNum.Items.Clear();
                CBListAllGuest.Items.Clear();
                CBRoomAvailDelete.Items.Clear();
                CBHousekeepingCreate.Items.Clear();
                housekeepingNum2.Items.Clear();
                ArrayList room = new ArrayList();
                room = roomAvailabilityDBManager.GetAllRooms();
                foreach (room h in room)
                {
                    
                    CBEditRoomNum.Items.Add(Convert.ToString(h.roomNum));
                    CBListAllGuest.Items.Add(Convert.ToString(h.roomNum));
                    CBRoomAvailDelete.Items.Add(Convert.ToString(h.roomNum));
                    CBHousekeepingCreate.Items.Add(Convert.ToString(h.roomNum));
                    housekeepingNum2.Items.Add(Convert.ToString(h.roomNum));
                }
            }
            else
            {
                if (tbxCreateRMFloor.Text == "")
                    lblCreateRoomValid3.Visible = true;
                if (tbxCreateRMType.Text == "")
                    lblCreateRoomValid2.Visible = true;
                if (tbxCreateRoomRates.Text == "")
                    lblCreateRoomValid4.Visible = true;
            }
        }

        private void btnEditRoomSearch_Click(object sender, EventArgs e)
        {
            if (CBEditRoomNum.Text != "")
            {
                EditRoomPanel2.Visible = true;
                int roomNum = Convert.ToInt32(CBEditRoomNum.SelectedItem);
                room r = new room();
                r = roomAvailabilityDBManager.GetRoomByRoomNum(roomNum);
                tbxEditRMFloor.Text = r.roomFloor;
                tbxEditRMRates.Text = Convert.ToString(r.roomRates);
                CBEditRMStatus.SelectedItem = r.Status;
                tbxEditRMType.Text = r.roomType;
            }
            else
            {
                MessageBox.Show("Please choose a room");
            }



        }

        private void btnEditRoomConfirm_Click(object sender, EventArgs e)
        {
            if (tbxEditRMType.Text != "" && tbxEditRMFloor.Text != "" && tbxEditRMRates.Text != "")
            {
                string floor = tbxEditRMFloor.Text;
                int rates = Convert.ToInt32(tbxEditRMRates.Text);
                string type = tbxEditRMType.Text;
                string status = Convert.ToString(CBEditRMStatus.SelectedItem);
                int roomNum = Convert.ToInt32(CBEditRoomNum.SelectedItem);

                var room = new room() { roomNum = roomNum, roomType = type, roomRates = rates, roomFloor = floor, Status = status };
                roomAvailabilityDBManager.UpdateRoom(room);
                MessageBox.Show("Room Successfully Edited!");
            }
            else
            {
                if (tbxEditRMType.Text == "")
                    valid1.Visible = true;
                if (tbxEditRMFloor.Text == "")
                    valid2.Visible = true;
                if (tbxEditRMRates.Text == "")
                    valid3.Visible = true;
            }
        }

        private void btnListAllGuestSearch_Click(object sender, EventArgs e)
        {
            int roomNum = Convert.ToInt32(CBListAllGuest.SelectedItem);
            ArrayList room = new ArrayList();
            room = ReportingDBManager.GetAllGuestSpecificRoom(roomNum);
            dataGridView2.DataSource = room;
        }

        private void btnViewAllGuestViewAll_Click(object sender, EventArgs e)
        {
            ArrayList Room = new ArrayList();
            Room = ReportingDBManager.GetAllGuestAllRoom();
            dataGridView2.DataSource = Room;
        }


        private void btnRMOccupancy2_Click(object sender, EventArgs e)
        {
            DateTime date = dateTimePicker2.Value;
            DateTime date2 = dateTimePicker3.Value;
            ArrayList Date = new ArrayList();
            Date = ReportingDBManager.RoomOccupancyReportForARangeofDates(date, date2);
            dataGridView3.DataSource = Date;
        }

        private void btnDeleteRM_Click(object sender, EventArgs e)
        {
            if (CBRoomAvailDelete.Text != "")
            {
                int roomNum = Convert.ToInt32(CBRoomAvailDelete.SelectedItem);
                roomAvailabilityDBManager.DeleteRoom(roomNum);
                MessageBox.Show("Room Deleted!");
                CBEditRoomNum.Items.Clear();
                CBListAllGuest.Items.Clear();
                CBRoomAvailDelete.Items.Clear();
                CBHousekeepingCreate.Items.Clear();
                housekeepingNum2.Items.Clear();
                CBEditRoomNum.Text = "";
                CBRoomAvailDelete.Text = "";
                EditRoomPanel2.Visible = false;
                ArrayList room = new ArrayList();
                room = roomAvailabilityDBManager.GetAllRooms();
                foreach (room h in room)
                {

                    CBEditRoomNum.Items.Add(Convert.ToString(h.roomNum));
                    CBListAllGuest.Items.Add(Convert.ToString(h.roomNum));
                    CBRoomAvailDelete.Items.Add(Convert.ToString(h.roomNum));
                    CBHousekeepingCreate.Items.Add(Convert.ToString(h.roomNum));
                    housekeepingNum2.Items.Add(Convert.ToString(h.roomNum));
                }
            }
            else
            {
                MessageBox.Show("Select A Room");
            }
        }

        private void btnHousekeepingCreate_Click(object sender, EventArgs e)
        {
            if (CBHousekeepingCreateStaff.Text != "" && CBHousekeepingCreate.Text !="")
            {
                int roomNum = Convert.ToInt32(CBHousekeepingCreate.SelectedItem);
                string staffName = Convert.ToString(CBHousekeepingCreateStaff.SelectedItem);
                string date = DTHousekeepingCreate.Text;
                string status = "Scheduled for Cleaning";
                var housekeeping = new housekeeping { roomNum = roomNum, staffName = staffName, date = date };
                housekeepingJhDBManager.InsertHousekeeping(housekeeping);
                var room = new room() { roomNum = roomNum, Status = status };
                roomAvailabilityDBManager.UpdateRoomStatus(room);
                MessageBox.Show("Schedule Created!");
                string dutyType = "Room";
                CBHousekeepingCreateStaff.Items.Clear();
                CBHousekeepingUpdate.Items.Clear();
                housekeepingNum3.Items.Clear();
                ArrayList staff = new ArrayList();
                staff = housekeepingJhDBManager.GetStaffByDutyType(dutyType);
                foreach (staff s in staff)
                {
                    CBHousekeepingCreateStaff.Items.Add(s.staffName);
                    CBHousekeepingUpdate.Items.Add(s.staffName);
                    housekeepingNum3.Items.Add(s.staffName);
                }
            }
            else
            {
                if(CBHousekeepingCreate.Text =="")
                    validCreate.Visible = true;
                if (CBHousekeepingCreateStaff.Text == "")
                    createValid.Visible = true;
            }
            
        }

        private void btnHousekeepingUpdateSearch_Click(object sender, EventArgs e)
        {
            if (CBHousekeepingUpdate.Text != "")
            {
                CBUpdateHousekeepingNum.Items.Clear();
                lblUpdatedHousekeeping.Visible = false;
                string staffName = Convert.ToString(CBHousekeepingUpdate.SelectedItem);
                ArrayList Staff = new ArrayList();
                Staff = housekeepingJhDBManager.GetDutyByStaffName(staffName);
                dataGridView4.DataSource = Staff;
                ArrayList housekeeping = new ArrayList();
                housekeeping = housekeepingJhDBManager.GetHouseNumByStaff(Convert.ToString(CBHousekeepingUpdate.SelectedItem));
                foreach (housekeeping r in housekeeping)
                {
                    CBUpdateHousekeepingNum.Items.Add(Convert.ToString(r.housekeepingNum));
                }
            }
            else
            {
                MessageBox.Show("Select A Staff");
            }

        }

        private void dataGridView4_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void btnHousekeepingUpdating_Click(object sender, EventArgs e)
        {
            if (housekeepingNum2.Text != "" && housekeepingNum3.Text != "" && CBUpdateHousekeepingNum.Text != "")
            {
                int roomNum = Convert.ToInt32(housekeepingNum2.SelectedItem);
                string staffName = Convert.ToString(housekeepingNum3.SelectedItem);
                int housekeepingNum = Convert.ToInt32(CBUpdateHousekeepingNum.SelectedItem);
                string date = DTHousekeepingUpdate.Text;
                var housekeeping = new housekeeping() { roomNum = roomNum, staffName = staffName, housekeepingNum = housekeepingNum, date = date };
                housekeepingJhDBManager.UpdateHousekeeping(housekeeping);
                MessageBox.Show("Schedule Updated!");
                string newinput = Convert.ToString(housekeepingNum3.SelectedItem);
                ArrayList Staff = new ArrayList();
                Staff = housekeepingJhDBManager.GetDutyByStaffName(newinput);
                dataGridView4.DataSource = Staff;
            }
            else
            {
                    MessageBox.Show("You left something blank");              
            }
        }

        private void CBHousekeepingUpdate_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void btnHousekeepingReport_Click(object sender, EventArgs e)
        {
            string date = DTHousekeepingReport.Text;
            ArrayList house = new ArrayList();
            house = housekeepingJhDBManager.GetHouseByDate(date);
            dataGridView5.DataSource = house;
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }

        private void btnListAllExport_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();

            Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
            Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
            app.Visible = true;
            worksheet = workbook.Sheets["Sheet1"];
            worksheet = workbook.ActiveSheet;
            worksheet.Name = "Exported from gridview";

            for (int i = 1; i < dataGridView2.Columns.Count + 1; i++)
            {
                worksheet.Cells[1, i] = dataGridView2.Columns[i - 1].HeaderText;
            }
            for (int i = 0; i < dataGridView2.Rows.Count ; i++)
            {
                for (int j = 0; j < dataGridView2.Columns.Count; j++)
                {
                    worksheet.Cells[i + 2, j + 1] = dataGridView2.Rows[i].Cells[j].Value.ToString();
                }
            }
            workbook.SaveAs("C:\\Users\\1104882d\\Desktop\\ListAllGuest.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
        }

        private void btnRoomOccupancyExport_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();

            Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
            Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
            app.Visible = true;
            worksheet = workbook.Sheets["Sheet1"];
            worksheet = workbook.ActiveSheet;
            worksheet.Name = "Exported from gridview";

            for (int i = 1; i < dataGridView3.Columns.Count + 1; i++)
            {
                worksheet.Cells[1, i] = dataGridView3.Columns[i - 1].HeaderText;
            }
            for (int i = 0; i < dataGridView3.Rows.Count; i++)
            {
                for (int j = 0; j < dataGridView3.Columns.Count; j++)
                {
                    worksheet.Cells[i + 2, j + 1] = dataGridView3.Rows[i].Cells[j].Value.ToString();
                }
            }
            workbook.SaveAs("C:\\Users\\1104882d\\Desktop\\RoomOccupancy.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
        }

        private void btnHousekeepingExport_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();

            Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
            Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
            app.Visible = true;
            worksheet = workbook.Sheets["Sheet1"];
            worksheet = workbook.ActiveSheet;
            worksheet.Name = "Exported from gridview";

            for (int i = 1; i < dataGridView4.Columns.Count + 1; i++)
            {
                worksheet.Cells[1, i] = dataGridView4.Columns[i - 1].HeaderText;
            }
            for (int i = 0; i < dataGridView4.Rows.Count - 1; i++)
            {
                for (int j = 0; j < dataGridView4.Columns.Count; j++)
                {
                    worksheet.Cells[i + 2, j + 1] = dataGridView4.Rows[i].Cells[j].Value.ToString();
                }
            }
            workbook.SaveAs("C:\\Users\\1104882d\\Desktop\\Housekeeping.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
        }

        #endregion

        #region CHEE HWA'S CODES
        private void btnGRFind_Click(object sender, EventArgs e)
        {
            tbxGRResult.Text = "Guest No. \t First Name \t Last Name \r\n";
            ArrayList result = BookingDBManager.GetListOfGuest(tbxGRName.Text);
            if (result.Count > 0)
                foreach (guest g in result)
                    tbxGRResult.Text += g.guestNo + " \t\t " + g.firstName + " \t\t " + g.lastName + "\r\n";
            else
                tbxGRResult.Text = "No guest found";
        }
        private void btnGERetrieve_Click(object sender, EventArgs e)
        {
            try
            {
                guest g = BookingDBManager.GetGuestByGuestNo(Convert.ToInt32(tbxGEGuestNo.Text));
                tbxGEFirstName.Text = g.firstName;
                tbxGELastName.Text = g.lastName;
                tbxGEPhoneNo.Text = g.phoneNo;
                tbxGEEmail.Text = g.email;
                tbxGEAddress.Text = g.address;
                tbxGEPostal.Text = g.postalCode;
                tbxGECountry.Text = g.country;
                tbxGERemarks.Text = g.remarks;
                tbxGERoomNo.Text = Convert.ToString(g.roomNum);
                dtpGECID.Value = g.checkIn;
                dtpGECIT.Value = g.checkIn;
                dtpGEDCOD.Value = g.desiredCheckOut;
                dtpGEDCOT.Value = g.desiredCheckOut;
                foreach (RadioButton rdb in pnlGETOB.Controls)
                    if (((RadioButton)rdb).Text == g.typeOfBed)
                        rdb.Checked = true;
                foreach (RadioButton rdb in pnlGETOR.Controls)
                    if (((RadioButton)rdb).Text == g.typeOfRoom)
                        rdb.Checked = true;
                foreach (RadioButton rdb in pnlGEPayment.Controls)
                    if (((RadioButton)rdb).Text == g.paymentMethod)
                        rdb.Checked = true;
                tbxGEAmount.Text = Convert.ToString(g.amountPaid);
            }
            catch
            {
                lblGEStatus.Text = "Guest is not found.";
            }
        }
        private void btnGEUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                guest oldGuest = new guest();
                oldGuest.guestNo = Convert.ToInt32(tbxGEGuestNo.Text);          // 1. guestNo
                oldGuest.firstName = tbxGEFirstName.Text;                       // 2. firstName
                oldGuest.lastName = tbxGELastName.Text;                         // 3. lastName
                oldGuest.phoneNo = tbxGEPhoneNo.Text;                           // 4. phoneNo
                oldGuest.email = tbxGEEmail.Text;                               // 5. email
                oldGuest.address = tbxGEAddress.Text;                           // 6. address
                oldGuest.postalCode = tbxGEPostal.Text;                         // 7. postalCode
                oldGuest.country = tbxGECountry.Text;                           // 8. country
                oldGuest.remarks = tbxGERemarks.Text;                           // 9. remarks
                oldGuest.roomNum = Convert.ToInt32(tbxGERoomNo.Text);           // 10. roomNum
                oldGuest.checkIn = dtpGECID.Value;                              // 
                oldGuest.checkIn = dtpGECIT.Value;                              // 11. checkIn
                oldGuest.desiredCheckOut = dtpGEDCOD.Value;                     //
                oldGuest.desiredCheckOut = dtpGEDCOT.Value;                     // 12. desiredCheckOut
                foreach (RadioButton rdb in pnlGETOB.Controls)
                    if (((RadioButton)rdb).Checked == true)
                        oldGuest.typeOfBed = ((RadioButton)rdb).Text;           // 13. typeOfBed
                foreach (RadioButton rdb in pnlGETOR.Controls)
                    if (((RadioButton)rdb).Checked == true)
                        oldGuest.typeOfRoom = ((RadioButton)rdb).Text;           // 14. typeOfRoom
                foreach (RadioButton rdb in pnlGEPayment.Controls)
                    if (((RadioButton)rdb).Checked == true)
                        oldGuest.paymentMethod = ((RadioButton)rdb).Text;       // 15. paymentMethod
                oldGuest.amountPaid = Convert.ToInt32(tbxGEAmount.Text);        // 16. amountPaid
                if (BookingDBManager.UpdateGuest(oldGuest) == 1)
                    lblGEStatus.Text = "Checked In";
                else
                    lblGEStatus.Text = "Fail";
            }
            catch
            {
                lblGEStatus.Text = "Guest not found";
            }
        }
        private void btnGCCreate_Click(object sender, EventArgs e)
        {
            guest newGuest = new guest();
            newGuest.firstName = tbxGCFirstName.Text;
            newGuest.lastName = tbxGCLastName.Text;
            newGuest.phoneNo = tbxGCPhoneNo.Text;
            newGuest.email = tbxGCEmail.Text;
            newGuest.address = tbxGCAddress.Text;
            newGuest.postalCode = tbxGCPostal.Text;
            newGuest.country = tbxGCCountry.Text;
            newGuest.remarks = tbxGCRemarks.Text;
            newGuest.roomNum = Convert.ToInt32(tbxGCRoomNo.Text);
            newGuest.checkIn = dtpGCCID.Value;
            newGuest.checkIn = dtpGCCIT.Value;
            newGuest.desiredCheckOut = dtpGCDCOD.Value;
            newGuest.desiredCheckOut = dtpGCDCOT.Value;
            foreach (RadioButton rdb in pnlGCTOB.Controls)
                if (((RadioButton)rdb).Checked == true)
                    newGuest.typeOfBed = ((RadioButton)rdb).Text;
            foreach (RadioButton rdb in pnlGCTOR.Controls)
                if (((RadioButton)rdb).Checked == true)
                    newGuest.typeOfRoom = ((RadioButton)rdb).Text;
            foreach (RadioButton rdb in pnlGCPayment.Controls)
                if (((RadioButton)rdb).Checked == true)
                    newGuest.paymentMethod = ((RadioButton)rdb).Text;
            newGuest.amountPaid = Convert.ToInt32(tbxGCAmount.Text);
            if (BookingDBManager.CreateGuest(newGuest) == 1)
                lblGCStatus.Text = "Checked In";
            else
                lblGCStatus.Text = "Failed";
        }
        private void btnCCCreate_Click(object sender, EventArgs e)
        {
            creditCard card = new creditCard();
            card.guestNo = Convert.ToInt32(tbxCCGuestNo.Text);                                                           // 1. guestNo
            card.cardNo = tbxCCCardNo1.Text + tbxCCCardNo2.Text + tbxCCCardNo3.Text + tbxCCCardNo4.Text;                 // 2. cardNo
            card.cFirstName = tbxCCFirstName.Text;                                                                       // 3. firstName
            card.cLastName = tbxCCLastName.Text;                                                                         // 4. lastName
            card.cardExpire = new DateTime(Convert.ToInt32(cbxCCExpireY.Text), Convert.ToInt32(cbxCCExpireM.Text), 1);   // 5. cardExpire
            card.cardSecurityNo = tbxCCSecurity.Text;                                                                    // 6. cardSecurityNo
            if (BookingDBManager.CreateCard(card) == 1)
                lblCCStatus.Text = "Created";
            else
                lblCCStatus.Text = "Failed";
        }
        private void btnBCCreate_Click(object sender, EventArgs e)
        {
            try
            {
                booking booking = new booking();
                ArrayList todayGuest = BookingDBManager.GetListOfGuestCheckedInToday();
                if (todayGuest.Count > 0)
                {
                    tbxBCResult.Text = "Guest No.: \t First Name:\t Last Name: \t Room No.: \r\n";
                    int count = 0;
                    foreach (guest g in todayGuest)
                    {
                        booking.guestNo = g.guestNo;
                        tbxBCResult.Text += g.guestNo + "\t";
                        booking.firstName = g.firstName;
                        tbxBCResult.Text += g.firstName + "\t";
                        booking.lastName = g.lastName;
                        tbxBCResult.Text += g.lastName + "\t";
                        booking.checkIn = g.checkIn;
                        booking.roomNum = g.roomNum;
                        tbxBCResult.Text += g.roomNum + "\r\n";
                        if (BookingDBManager.CreateBooking(booking) == 1)
                            count++;
                        else
                            tbxBCResult.Text += "Above guest unable to create booking";
                    }
                    tbxBCResult.Text += "Number of bookings created: " + count;
                }
                else
                {
                    tbxBCResult.Text = "No guest found";
                }
            }
            catch (Exception ex)
            {
                tbxBCResult.Text = Convert.ToString(ex);
            }
        }
        private void btnCOGRFind_Click(object sender, EventArgs e)
        {
            tbxCOGRResult.Text = "Guest No. \t First Name \t Last Name \r\n";
            ArrayList result = BookingDBManager.GetListOfGuest(tbxCOGRName.Text);
            if (result.Count > 0)
                foreach (guest g in result)
                    tbxCOGRResult.Text += g.guestNo + " \t\t " + g.firstName + " \t\t " + g.lastName + "\r\n";
            else
                tbxCOGRResult.Text = "No guest found";
        }
        private void btnCOGEUpdate_Click(object sender, EventArgs e)
        {
            guest oldGuest = new guest();
            oldGuest.guestNo = Convert.ToInt32(tbxCOGEGuestNo.Text);
            oldGuest.checkOut = dtpGECheckOutD.Value;
            oldGuest.checkOut = dtpGECheckOutT.Value;
            if (BookingDBManager.CheckOutGuest(oldGuest) == 1)
                lblCOGEStatus.Text = "Checked Out";
            else
                lblCOGEStatus.Text = "Fail";
        }
        private void btnBEUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                booking booking = new booking();
                ArrayList todayGuest = BookingDBManager.GetListOfGuestCheckedOutToday();
                if (todayGuest.Count > 0)
                {
                    tbxBEResult.Text = "Guest No.: \t First Name:\t Last Name: \t Room No.: \r\n";
                    int count = 0;
                    foreach (guest g in todayGuest)
                    {
                        booking.guestNo = g.guestNo;
                        tbxBEResult.Text += g.guestNo + "\t";
                        booking.firstName = g.firstName;
                        tbxBEResult.Text += g.firstName + "\t";
                        booking.lastName = g.lastName;
                        tbxBEResult.Text += g.lastName + "\t";
                        booking.checkIn = g.checkIn;
                        booking.roomNum = g.roomNum;
                        tbxBEResult.Text += g.roomNum + "\r\n";
                        count++;
                        if (BookingDBManager.UpdateBooking(booking) == 1)
                            count++;
                        else
                            tbxBCResult.Text += "Above guest unable to update booking";
                    }
                    tbxBEResult.Text += "Number of bookings updated: " + count;
                }
                else
                {
                    tbxBEResult.Text = "No guest found";
                }
            }
            catch
            {
                tbxBEResult.Text = "No guest found";
            }
        }
        private void btnCOGenerateInvoice_Click(object sender, EventArgs e)
        {
            try
            {
                guest oldGuest = BookingDBManager.GetGuestByGuestNo(Convert.ToInt32(tbxCOPayment.Text));
                int totalCost = 0;
                if (ckbCOItem1.Checked == true)
                    totalCost += Convert.ToInt32(cbbCOItem1.Text) * 12; // Beer
                if (ckbCOItem2.Checked == true)
                    totalCost += Convert.ToInt32(cbbCOItem2.Text) * 2; // Mineral Water
                if (ckbCOItem3.Checked == true)
                    totalCost += Convert.ToInt32(cbbCOItem3.Text) * 2; // Coke
                if (ckbCOItem4.Checked == true)
                    totalCost += Convert.ToInt32(cbbCOItem4.Text) * 2; // Toilet Paper
                if (ckbCOItem5.Checked == true)
                    totalCost += Convert.ToInt32(cbbCOItem5.Text) * 8; // Soap
                if (ckbCOItem6.Checked == true)
                    totalCost += Convert.ToInt32(cbbCOItem6.Text) * 8; // Shampoo
                if (ckbCOItem7.Checked == true)
                    totalCost += Convert.ToInt32(cbbCOItem7.Text) * 2; // Local area map
                if (ckbCOItem8.Checked == true)
                    totalCost += Convert.ToInt32(cbbCOItem8.Text) * 5; // Snacks
                lblCOPaymentStatus.Text = "Guest Paid: " + oldGuest.amountPaid + "\r\nTotal Cost: $" + totalCost;
                System.Diagnostics.Process.Start("calc");
            }
            catch (Exception ex)
            {
                lblCOPaymentStatus.Text = Convert.ToString(ex);
            }
        }
        private void btnCOGRDelete_Click(object sender, EventArgs e)
        {
            int gCount = 0;
            int cCount = 0;
            int bCount = 0;
            string fail = "";
            try
            {
                ArrayList result = BookingDBManager.GetListOfGuest("");
                foreach (guest g in result)
                {
                    if (g.checkOut.AddYears(5).Year < System.DateTime.Now.Year)
                    {
                        if (BookingDBManager.DeleteGuest(g.guestNo) == 1)
                            gCount++;
                        else
                            fail += "For guest record: " + g.guestNo + "\r\n";
                        if (g.paymentMethod == "Credit Card")
                        {
                            if (BookingDBManager.DeleteCard(g.guestNo) == 1)
                                cCount++;
                            else
                                fail += "For credit card record: " + g.guestNo + "\r\n";
                        }
                        if (BookingDBManager.DeleteBooking(g.guestNo) == 1)
                            bCount++;
                        else
                            fail += "For booking record: " + g.guestNo + "\r\n";
                    }
                    if (g.checkIn.AddYears(5).Year < System.DateTime.Now.Year)
                    {
                        if (BookingDBManager.DeleteGuest(g.guestNo) == 1)
                            gCount++;
                        else
                            fail += "For guest record: " + g.guestNo + "\r\n";
                        if (g.paymentMethod == "Credit Card")
                        {
                            if (BookingDBManager.DeleteCard(g.guestNo) == 1)
                                cCount++;
                            else
                                fail += "For credit card record: " + g.guestNo + "\r\n";
                        }
                        if (BookingDBManager.DeleteBooking(g.guestNo) == 1)
                            bCount++;
                        else
                            fail += "For booking record: " + g.guestNo + "\r\n";
                    }
                }
                tbxCOGRDeleteStatus.Text = fail + "\r\nAbove guest number are guests which are not deleted."
                    + "\r\nNumber of guest records deleted: " + gCount + "\r\nNumber of credit card records deleted: " + cCount
                    + "\r\nNumber of booking records deleted: " + bCount;
            }
            catch (Exception ex)
            {
                tbxCOGRDeleteStatus.Text = Convert.ToString(ex);
            }
        }
        #endregion

        #region ZHI XIAN'S CODES
        private void btnCreate_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Are you sure you create a staff?", "Confirmation", MessageBoxButtons.YesNo);
            if (dialogResult == DialogResult.No)
                return;
            string staffName = tbxStaffName.Text;
            string staffType = cbbStaffType.Text;
            string dob = tbxDob.Text;
            string bankNum = tbxBankNum.Text;
            string homeAdd = tbxHomeAdd.Text;
            string phoneNum = tbxPhoneNum.Text;
            string dutyType = cbbDutyType.Text;
            staff m = new staff(staffName, staffType, dob, bankNum, homeAdd, phoneNum, dutyType);
            try
            {
                StaffDBManager.InsertStaff(m);
                lblCreate.Text = "Staff created successfully!";
            }
            catch (SqlException ex)
            {
                lblCreate.Text = "Failed to create staff, exception message: " + ex.Message;
            }
        }

        private void btnRetrievebyDuty_Click(object sender, EventArgs e)
        {
            string staffName = tbxRetrieveName.Text;
            try
            {
                staff m = StaffDBManager.GetStaffByStaffName(staffName);

                lblSType.Text = m.staffType;
                lblBob.Text = m.dob;
                lblBank.Text = m.bankNum;
                lblAddr.Text = m.homeAdd;
                lblPhone.Text = m.phoneNum;
                lblDuty.Text = m.dutyType;
            }
            catch (NullReferenceException) // ne removed
            {
                lblRen.Text = "Failed to retrieve, staff does not exist";
            }
            catch (SqlException ex)
            {
                lblRen.Text = "Failed to retrieve, exception message: " + ex.Message;
            }

        }

        private void btnRetrieveID_Click(object sender, EventArgs e)
        {
            if (tbxRetrieveId.Text != "")
            {

                int staffNum = Convert.ToInt16(tbxRetrieveId.Text);
                try
                {
                    staff m = StaffDBManager.GetStaffById(staffNum);
                    tbxStaff.Text = m.staffName;
                    cmbStaffTypeU.Text = m.dutyType;
                    cmbDutyTypeU.Text = m.dutyType;
                    tbxDateofBirth.Text = m.dob;
                    tbxBank.Text = m.bankNum;
                    tbxHome.Text = m.homeAdd;
                    tbxPhone.Text = m.phoneNum;
                }
                catch (NullReferenceException) // ne removed
                {
                    lblUpdate.Text = "Failed to retrieve, staff does not exist";
                }
                catch (SqlException ex)
                {
                    lblUpdate.Text = "Failed to retrieve, exception message: " + ex.Message;
                }
            }
            else
            {
                tbxRetrieveId.Visible = true;
            }

        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Are you sure you want to update information about this staff?", "Confirmation", MessageBoxButtons.YesNo);
            if (dialogResult == DialogResult.No)
                return;
            int staffNum = Convert.ToInt16(tbxRetrieveId.Text);
            string staffName = tbxStaff.Text;
            string staffType = cmbStaffTypeU.Text;
            string dob = tbxDateofBirth.Text;
            string bankNum = tbxBank.Text;
            string homeAdd = tbxHome.Text;
            string phoneNum = tbxPhone.Text;
            string dutyType = cmbDutyTypeU.Text;

            staff m = new staff(staffNum, staffName, staffType, dob, bankNum, homeAdd, phoneNum, dutyType);
            try
            {
                StaffDBManager.UpdateStaff(m);
                lblUpdate.Text = "Staff Updated!";
            }
            catch (SqlException ex)
            {
                lblUpdate.Text = "Staff not Updated! Exception message: " + ex.Message;
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (tbxNumber.Text != "")
            {

                DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this staff?", "Confirmation", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.No)
                    return;
                int snum = Convert.ToInt16(tbxNumber.Text);
                try
                {
                    StaffDBManager.DeleteStaff(snum);
                    lblDel.Text = "Staff deleted succesfful.";
                }
                catch (SqlException ex)
                {
                    lblDel.Text = " Failed to delete staff. Exception message " + ex.Message;
                }
            }
            else 
            {
                lblDelete.Visible = true;

        }
        }
        #endregion

        private void valid1_Click(object sender, EventArgs e)
        {
            if (tbxRetrieveId.Text == "")
            {
                lblId.Visible = true;
            }
        }

        private void tbxRetrieveId_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnRoomStatusReportAll_Click(object sender, EventArgs e)
        {
            ArrayList all = new ArrayList();
            all = roomAvailabilityDBManager.GetAllRooms();
            dataGridView1.DataSource = all;
        }

        private void logOutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Login obiform2 = new Login();
            this.Hide();
            obiform2.Show();
        }

        //#region XIAO LING'S CODES
        //private void btnCreate_Click(object sender, EventArgs e)
        //{
        //    DialogResult dialogResult = MessageBox.Show("Are you sure you create a staff?", "Confirmation", MessageBoxButtons.YesNo);
        //    if (dialogResult == DialogResult.No)
        //        return;
        //    string staffName = tbxStaffName.Text;
        //    string staffType = cbbStaffType.Text;
        //    string dob = tbxDob.Text;
        //    string bankNum = tbxBankNum.Text;
        //    string homeAdd = tbxHomeAdd.Text;
        //    string phoneNum = tbxPhoneNum.Text;
        //    string dutyType = cbbDutyType.Text;
        //    Staff m = new Staff(staffName, staffType, dob, bankNum, homeAdd, phoneNum, dutyType);
        //    try
        //    {
        //        StaffDBManager.InsertStaff(m);
        //        lblCreate.Text = "Staff created successfully!";
        //    }
        //    catch (SqlException ex)
        //    {
        //        lblCreate.Text = "Failed to create staff, exception message: " + ex.Message;
        //    }

        //}

        //private void btnRetrieve_Click(object sender, EventArgs e)
        //{

        //    string staffName = tbxRetrieveName.Text;
        //    try
        //    {
        //        Staff m = StaffDBManager.GetStaffByStaffName(staffName);

        //        lblSType.Text = m.staffType;
        //        lblBob.Text = m.dob;
        //        lblBank.Text = m.bankNum;
        //        lblAddr.Text = m.homeAdd;
        //        lblPhone.Text = m.phoneNum;
        //        lblDuty.Text = m.dutyType;
        //    }
        //    catch (NullReferenceException ne)
        //    {
        //        lblRen.Text = "Failed to retrieve, staff does not exist";
        //    }
        //    catch (SqlException ex)
        //    {
        //        lblRen.Text = "Failed to retrieve, exception message: " + ex.Message;
        //    }


        //}

        //private void btnUpdate_Click(object sender, EventArgs e)
        //{
        //    DialogResult dialogResult = MessageBox.Show("Are you sure you want to update information about this staff?", "Confirmation", MessageBoxButtons.YesNo);
        //    if (dialogResult == DialogResult.No)
        //        return;
        //    int staffNum = Convert.ToInt16(tbxRetrieveId.Text);
        //    string staffName = tbxStaff.Text;
        //    string staffType = cmbStaffTypeU.Text;
        //    string dob = tbxDateofBirth.Text;
        //    string bankNum = tbxBank.Text;
        //    string homeAdd = tbxHome.Text;
        //    string phoneNum = tbxPhone.Text;
        //    string dutyType = cmbDutyTypeU.Text;

        //    Staff m = new Staff(staffNum, staffName, staffType, dob, bankNum, homeAdd, phoneNum, dutyType);
        //    try
        //    {
        //        StaffDBManager.UpdateStaff(m);
        //        lblUpdate.Text = "Staff Updated!";
        //    }
        //    catch (SqlException ex)
        //    {
        //        lblUpdate.Text = "Staff not Updated! Exception message: " + ex.Message;
        //    }
        //}

        //private void btnDelete_Click(object sender, EventArgs e)
        //{
        //    DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this staff?", "Confirmation", MessageBoxButtons.YesNo);
        //    if (dialogResult == DialogResult.No)
        //        return;
        //    int snum = Convert.ToInt16(tbxNumber.Text);
        //    try
        //    {
        //        StaffDBManager.DeleteStaff(snum);
        //        lblDel.Text = "Staff deleted succesfful.";
        //    }
        //    catch (SqlException ex)
        //    {
        //        lblDel.Text = " Failed to delete staff. Exception message " + ex.Message;
        //    }

        //}


        //private void btnRetrieveID_Click(object sender, EventArgs e)
        //{
        //    int staffNum = Convert.ToInt16(tbxRetrieveId.Text);
        //    try
        //    {
        //        Staff m = StaffDBManager.GetStaffById(staffNum);
        //        tbxStaff.Text = m.staffName;
        //        cmbStaffTypeU.Text = m.dutyType;
        //        cmbDutyTypeU.Text = m.dutyType;
        //        tbxDateofBirth.Text = m.dob;
        //        tbxBank.Text = m.bankNum;
        //        tbxHome.Text = m.homeAdd;
        //        tbxPhone.Text = m.phoneNum;
        //    }
        //    catch (NullReferenceException ne)
        //    {
        //        lblUpdate.Text = "Failed to retrieve, staff does not exist";
        //    }
        //    catch (SqlException ex)
        //    {
        //        lblUpdate.Text = "Failed to retrieve, exception message: " + ex.Message;
        //    }

        //}

        //private void cmbDutyTypeU_SelectedIndexChanged(object sender, EventArgs e)
        //{

        //}
        //#endregion

    }
}







